package 单例;

/**
 * @Author Klys
 * @Date 2023/3/5 13:51
 * @Description
 * @Version 1.0
 */

//懒汉式   线程不安全类
public class Lazy1 {

    //创建一个Lazy对象    懒汉式不new
    private static Lazy1 instance;

    //让构造函数为 private，这样该类就不会被实例化
    private Lazy1() {

    }

    //对外暴露获取唯一可用的对象
    public static Lazy1 getInstance() {
        if (instance == null) {
            instance = new Lazy1();
        }
        return instance;
    }

    public void sayHello() {
        System.out.println("Hello");
    }
}
